<?php
/**
 *	This file is part of rtfdoc.
 *
 *	rtfdoc is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	rtfdoc is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with rtfdoc.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
require_once dirname(realpath(__FILE__)) . '/RTFDocumentHeaderView.php';
require_once dirname(realpath(__FILE__)) . '/RTFDocumentBodyView.php';
class RTFDocumentView
{
    /**
     * @var RTFDocument
     */
    public $model;
    /**
     * holds the rtf-text
     *
     * @var string
     */
    private $rtf_text;
    public function parse(RTFDocument $model)
    {
        $this->model = $model;
        $this->rtf_text = $this->getDocumentTemplate();
        $this->rtf_text = sprintf($this->rtf_text, $this->buildHeader(), $this->buildDocument());
        return $this->rtf_text;
    }
    /**
     * 2 parts:
     * - header
     * - document
     *
     * @return string
     */
    public function getDocumentTemplate()
    {
        $tpl = '{%s%s}';
        return $tpl;
    }
    /**
     * builds the header
     *
     * @return string
     */
    private function buildHeader()
    {
        $view = new RTFDocumentHeaderView();
        return $view->parse($this->model);
    }
    /**
     * builds the document
     *
     * @return string
     */
    private function buildDocument()
    {
        $view = new RTFDocumentBodyView();
        return $view->parse($this->model);
    }
}
?>